package com.coo1.onlineorder.server;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.coo1.onlineorder.server.data.MSTADMIN;

public class TestSignUpServlet extends HttpServlet implements java.io.Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {

		
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		
		if (username == null) {
			username = "(No username)";
		}
		
        PersistenceManager pm = PMF.get().getPersistenceManager();

        MSTADMIN m = new MSTADMIN(username, password, null);

        try {
            pm.makePersistent(m);
        } finally {
            pm.close();
        }
        pm = PMF.get().getPersistenceManager();

		Query query = pm.newQuery(MSTADMIN.class,"username == USERNAMEParam");
    	query.declareParameters("String USERNAMEParam");



			List<MSTADMIN> results = (List<MSTADMIN>) query.execute(username);
			HttpSession   Session   =   req.getSession(true); 
			
			Session.setAttribute("USERNAME", results.get(0).getUserName());
		    Session.setAttribute("PASSWORD", results.get(0).getPassword());

			resp.sendRedirect("/TestMailSending.jsp");

        

}

	
	
}